//deck.cpp
/********************************************************************************
*																				*
*	Author:			Vanessa Starkey												*
*	Assignment:		Assignment 8												*
*	Class:			CPS-151														*
*	Instructor:		V. Starkley													*
*	Due Date:		November 7													*
*																				*
*	This file implements the deck class.										*
*																				*
********************************************************************************/

#include <iostream>
#include <ctime>
using namespace std;
#include "deck.h"
#include  "card.h"

//helper function declaration

void swap(Card& c1, Card& c2);
//pre:  c1 and c2 have values
//post:  suit and value of c1 and c2 are swapped


Deck::Deck()
{
	int i=0;
	for (int s=C;s<4;s++)
    {
   	for (int v=2;v<15;v++)
      {
         d[i].theSuit = static_cast<Suit>(s);
         d[i].theValue= static_cast<Value>(v);
         i++;
      }
    }
    position = 0;
}

void Deck::Shuffle()
{
	int r;
	srand(static_cast<unsigned int>(time(0)));   //initialize random number generator
	for(int i=0;i<52;i++)
	{
   		r = rand() % 52;				//generate random number between 0 and 51
		swap(d[r],d[i]);
	}
}

Card Deck::getTopCard()
{
	position++;
	return d[position-1];
}

void Deck::displayDeck(ostream& fout)
{
	for (int i=0;i<52;i++)
		fout << d[i] << endl;
}


void Deck::ResetDeck()
{
	position = 0;
}


void swap(Card& c1, Card& c2)
{
	Card temp;
    temp=c1;
    c1=c2;
    c2=temp;
}

